package cn.iocoder.yudao.module.eval.dal.mysql.score;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.eval.controller.admin.score.vo.EvalScoreRecordPageReqVO;
import cn.iocoder.yudao.module.eval.dal.dataobject.score.EvalScoreRecordDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 评分数据 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface EvalScoreRecordMapper extends BaseMapperX<EvalScoreRecordDO> {

    default PageResult<EvalScoreRecordDO> selectPage(EvalScoreRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EvalScoreRecordDO>()
                .eqIfPresent(EvalScoreRecordDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(EvalScoreRecordDO::getSubjectId, reqVO.getSubjectId())
                .eqIfPresent(EvalScoreRecordDO::getCandidateId, reqVO.getCandidateId())
                .eqIfPresent(EvalScoreRecordDO::getEvaluatorId, reqVO.getEvaluatorId())
                .eqIfPresent(EvalScoreRecordDO::getScoreStatus, reqVO.getScoreStatus())
                .eqIfPresent(EvalScoreRecordDO::getIsPassed, reqVO.getIsPassed())
                .eqIfPresent(EvalScoreRecordDO::getIsReviewed, reqVO.getIsReviewed())
                .betweenIfPresent(EvalScoreRecordDO::getSubmitTime, reqVO.getSubmitTime())
                .betweenIfPresent(EvalScoreRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(EvalScoreRecordDO::getId));
    }

    default List<EvalScoreRecordDO> selectListByPlanId(Long planId) {
        return selectList(EvalScoreRecordDO::getPlanId, planId);
    }

    default List<EvalScoreRecordDO> selectListBySubjectId(Long subjectId) {
        return selectList(EvalScoreRecordDO::getSubjectId, subjectId);
    }

    default List<EvalScoreRecordDO> selectListByCandidateId(Long candidateId) {
        return selectList(EvalScoreRecordDO::getCandidateId, candidateId);
    }

    default List<EvalScoreRecordDO> selectListByEvaluatorId(Long evaluatorId) {
        return selectList(EvalScoreRecordDO::getEvaluatorId, evaluatorId);
    }

    default List<EvalScoreRecordDO> selectListByPlanIdAndCandidateId(Long planId, Long candidateId) {
        return selectList(new LambdaQueryWrapperX<EvalScoreRecordDO>()
                .eq(EvalScoreRecordDO::getPlanId, planId)
                .eq(EvalScoreRecordDO::getCandidateId, candidateId));
    }

    default List<EvalScoreRecordDO> selectListBySubjectIdAndCandidateId(Long subjectId, Long candidateId) {
        return selectList(new LambdaQueryWrapperX<EvalScoreRecordDO>()
                .eq(EvalScoreRecordDO::getSubjectId, subjectId)
                .eq(EvalScoreRecordDO::getCandidateId, candidateId));
    }

    default List<EvalScoreRecordDO> selectListByPlanIdAndSubjectId(Long planId, Long subjectId) {
        return selectList(new LambdaQueryWrapperX<EvalScoreRecordDO>()
                .eq(EvalScoreRecordDO::getPlanId, planId)
                .eq(EvalScoreRecordDO::getSubjectId, subjectId));
    }

    default List<EvalScoreRecordDO> selectListByScoreStatus(Integer scoreStatus) {
        return selectList(EvalScoreRecordDO::getScoreStatus, scoreStatus);
    }

    default List<EvalScoreRecordDO> selectListByScoreStatuses(Collection<Integer> scoreStatuses) {
        return selectList(new LambdaQueryWrapperX<EvalScoreRecordDO>()
                .in(EvalScoreRecordDO::getScoreStatus, scoreStatuses));
    }

    default EvalScoreRecordDO selectByPlanSubjectCandidateEvaluator(Long planId, Long subjectId, Long candidateId, Long evaluatorId) {
        return selectOne(new LambdaQueryWrapperX<EvalScoreRecordDO>()
                .eq(EvalScoreRecordDO::getPlanId, planId)
                .eq(EvalScoreRecordDO::getSubjectId, subjectId)
                .eq(EvalScoreRecordDO::getCandidateId, candidateId)
                .eq(EvalScoreRecordDO::getEvaluatorId, evaluatorId));
    }

    default List<EvalScoreRecordDO> selectList(EvalScoreRecordPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<EvalScoreRecordDO>()
                .eqIfPresent(EvalScoreRecordDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(EvalScoreRecordDO::getSubjectId, reqVO.getSubjectId())
                .eqIfPresent(EvalScoreRecordDO::getCandidateId, reqVO.getCandidateId())
                .eqIfPresent(EvalScoreRecordDO::getEvaluatorId, reqVO.getEvaluatorId())
                .eqIfPresent(EvalScoreRecordDO::getScoreStatus, reqVO.getScoreStatus())
                .eqIfPresent(EvalScoreRecordDO::getIsPassed, reqVO.getIsPassed())
                .eqIfPresent(EvalScoreRecordDO::getIsReviewed, reqVO.getIsReviewed())
                .betweenIfPresent(EvalScoreRecordDO::getSubmitTime, reqVO.getSubmitTime())
                .betweenIfPresent(EvalScoreRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(EvalScoreRecordDO::getId));
    }

}
